home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 July / EnigmA AMIGA RUN 20 (1997)(G.R. Edizioni)(IT)[!][issue 1997-07 & 08][EAR-CD IV].iso / lightwave / arexx_macros / lwscenemacros / chkscene.rexx next >
OS/2 REXX Batch file  |  1994-09-05  |  7KB  |  227 lines

  1. /*
  2.    ChkScene.rexx
  3.  
  4.    Copyright (C) 1994 Earl C. Terwilliger
  5.                 Phone (606)-723-5718
  6.  
  7.       Internet: AISTERWI@ACS.EKU.EDU
  8.    Conmpuserve: 70575,1330
  9.  
  10.    Non-Commercial USE granted to ALL !!!
  11.  
  12.    One of the problems with giving a LW scene
  13.    to someone else is that you have to give
  14.    the other files that are referenced in
  15.    the scene file and referenced in the
  16.    objects files (such as texture maps and
  17.    reflection maps, etc.) too.
  18.  
  19.    You can easily forget to include a file when
  20.    copying your scene, object and image files
  21.    files to diskette.
  22.  
  23.    ChkScene.rexx checks a Lightwave Scene file
  24.    and objects files it references to make sure
  25.    that the file names referenced in them do
  26.    indeed exist. If a file is not found that
  27.    is referenced, an error message and the
  28.    error reason is displayed. Some files which
  29.    are reported as not found are ok since they
  30.    may refer to files created via the SAVE RGB
  31.    or Save Anim LW scene commands. Also some
  32.    files referencing the supplied LW sample
  33.    objects may not be found if no specific
  34.    drive:directory reference is given, however
  35.    they will load OK in LW layout even though
  36.    ChkScene reports the file is not found.
  37.  
  38.    Syntax: rx ChkScene [drive:directory/]LW-Scene-File
  39.  
  40.  
  41.    NOTE: The ChkScene.rexx script checks a
  42.    single LW scene file, whereas another script
  43.    called ChkScenes.rexx checks a whole drive:[directory]
  44.    structure for all LW scene files it finds.
  45.  
  46. */
  47.  
  48. /* TRACE(RESULTS) */
  49.  
  50. OPTIONS RESULTS
  51.  
  52. parse arg file
  53. if arg() = 0 then call syntax()
  54. if ~exists(file) then call syntax()
  55.  
  56. if (index(file,':') ~= 0) then do
  57.      temp = translate(file,"  ","/:"," ")
  58.      tempwords = words(temp)
  59.      name = word(temp,tempwords)
  60.      source = left(file,length(file)-length(name))
  61. end  
  62. else source = pragma('D')
  63. if (right(source,1) ~= ':') then do
  64.     if (right(source,1) ~= '/') then source = source||'/'
  65. end
  66.  
  67. if ~show('L',"rexxsupport.library") then do
  68.     if addlib('rexxsupport.library',0,-30,0) then
  69.         say "Added rexxsupport.library."
  70.     else do
  71.         say "Error: addlib() of rexxsupport.library failed."
  72.         exit 10
  73.     end
  74. end
  75.  
  76. open('infile',file,'R')
  77. instring=readln('infile')
  78.  
  79. if (pos('LWSC',instring) ~= 1) then do
  80.   close('infile')
  81.   say file' is not a LW scene file!'
  82.   exit(10)
  83. end
  84.  
  85. say
  86. say '[Input  Scene File Name]'file
  87.  
  88. do while eof('infile')=0
  89.      instring = readln('infile')
  90.      lwcmd = word(instring,1)
  91.      c = index(lwcmd,'Load')
  92.      if (index(instring,':') ~= 0) then do
  93.          if (index(instring,'/') ~= 0) then c = c + 1
  94.      end
  95.      if (c > 0) then do
  96.         filename = word(instring,2)
  97.         if (index(instring,':') = 0) then do
  98.             if (left(filename,1) ~= '/') then filename = source||filename
  99.             else filename = source||strip(filename,'L','/')
  100.         end
  101.         temp = upper(translate(filename,"  ","/:"," "))
  102.         c = showlist('A',word(temp,1))
  103.         c = c + showlist('H',word(temp,1))
  104.         if (c = 0) then do
  105.              say instring
  106.              call errmsg('Volume Not Mounted -  ERROR')
  107.         end
  108.         else if (~exists(filename)) then do
  109.                   temp = translate(filename,"  ","/:"," ")
  110.                   tempwords = words(temp)
  111.                   name = word(temp,tempwords)
  112.                   objname = source||'objects/'||name
  113.                   if (exists(objname)) then do
  114.                       say filename 'exists as' objname
  115.                       filename = objname
  116.                       if (index(lwcmd,"LoadObject") ~= 0) then call readlwob()
  117.                   end
  118.                   else do
  119.                       say instring
  120.                       call errmsg('File Not Found -  ERROR')
  121.                   end
  122.              end
  123.         else do
  124.             say instring ' [OK]'
  125.             if (index(lwcmd,"LoadObject") ~= 0) then call readlwob()
  126.         end
  127.      end
  128. end
  129. close('infile')
  130. say '<- Check Scene completed ->'
  131. exit 0
  132.  
  133. syntax:
  134. say
  135. say 'Syntax: rx ChkScene [drive:directory/]LW-Scene-File'
  136. say 
  137. exit 10
  138.  
  139. readlwob: PROCEDURE EXPOSE source filename
  140. OPTIONS RESULTS
  141.  
  142. open('lwobfile',filename,'R')
  143. objstring = readch('lwobfile',12)
  144.  
  145. type = substr(objstring,9,4)
  146.  
  147. if (type ~= "LWOB") then do
  148.   close('lwobfile')
  149.   say filename
  150.   call errmsg('This is not a LW Object file! - ERROR')
  151.   return 10
  152. end
  153.  
  154. form   = substr(objstring,1,4)
  155. length = c2d(substr(objstring,5,4),4)
  156. length = length + 8
  157.  
  158. say 'Reading from' filename
  159. /* say 'Object file length is' length 'bytes' */
  160.  
  161. open('lwobout',destname,'W')
  162.  
  163. do while eof('lwobfile')=0
  164.     objstring=readch('lwobfile',8)
  165.     if (eof('lwobfile') = 1) then break
  166.     chunk  = substr(objstring,1,4)
  167.     length = c2d(substr(objstring,5,4),4)
  168.     /* say 'Chunk Type is' chunk 'with a length of' length 'bytes' */
  169.     if (chunk ~= "SURF") then seek('lwobfile',length,'C')
  170.     else do
  171.         objstring = readch('lwobfile',length)
  172.         surfacepos = pos('00'x,objstring,1)
  173.         surface  = substr(objstring,1,(surfacepos-1))
  174.         surfacepos = surfacepos + (surfacepos // 2) + 1
  175.         say 'Surface Name:' surface
  176.         do while (surfacepos < length)
  177.             subchunk = substr(objstring,surfacepos,4)
  178.             /* say 'Subchunk  ' subchunk */
  179.             surfacepos = surfacepos + 4
  180.             len = c2d(substr(objstring,surfacepos,2),4)
  181.             surfacepos = surfacepos + 2
  182.             image = ""
  183.             if (subchunk = "TIMG") then do
  184.                 image = strip(substr(objstring,surfacepos,len),'T','00'x)
  185.                 say 'Texture Image ->' image
  186.             end
  187.             if (subchunk = 'RIMG') then do
  188.                 image = strip(substr(objstring,surfacepos,len),'T','00'x)
  189.                 say 'Reflection Image ->' image
  190.             end
  191.             if (image = "(none)") then image = ""
  192.             if (image ~= "") then do
  193.                 if (index(image,':') = 0) then do
  194.                     if (left(image,1) ~= '/') then fullimage = source||image
  195.                     else fullimage = source||strip(image,'L','/')
  196.                 end
  197.                 else fullimage = image
  198.                 temp = translate(fullimage,"  ","/:"," ")
  199.                 tempwords = words(temp)
  200.                 name = word(temp,tempwords)
  201.                 directory = left(fullimage,length(fullimage)-length(name))
  202.                 if (~exists(directory)) then do
  203.                     if (exists(source||"images")) then fullimage = source||'images/'||name
  204.                 end
  205.                 if (index(image,"(sequence)",1) = 0) then do
  206.                     if (~exists(fullimage)) then  do
  207.                          say fullimage
  208.                          call errmsg('File Not Found - ERROR')
  209.                      end
  210.                 end    
  211.             end
  212.             surfacepos = surfacepos + len
  213.         end
  214.     end
  215. end
  216.  
  217. close('lwobfile')
  218. return 0
  219.  
  220. errmsg: procedure
  221. parse arg msg
  222. len = length(msg) - 1
  223. errmsg = '|___________________________________________________________________________'
  224. errmsg = overlay(msg,errmsg,length(errmsg)-len,len+1)
  225. say errmsg
  226. return 0
  227.